<?php

namespace App\Http\Middleware;

use Closure;
use Dingo\Api\Exception\ResourceException;

class AssetPassword
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $user = auth('api')->user();
        if($user->asset_password) {
            if(!Hash::check(request('asset_password'),$user->asset_password )) {
                throw new ResourceException('error',[['error_code'=>'500001','message'=>'资金密码错误！']]);

            }
        }
        return $next($request);
    }
}
